import { request } from 'umi';

export type LoginParamsType = {
  phone: string;
  password: string;
  imageCode: string;
  imageCodeKey: string;
};

export type ImageCodeType = {
  imageCodeKey: string;
  imageCodeBase64: string;
};

export type GetMessageParamsType = {
  phone: string;
  imageCode: string;
  imageCodeKey: string;
};

export type UpdateKeyParamsType = {
  phone: string;
  messageCode: string;
  newLoginKey: string;
};

// 1. 获取图片验证码
export async function getImageCode() {
  return request<{ imageCodeKey: string; imageCodeBase64: string }>('/loginManage/getImageCode', {
    method:'get',
  });
}

// 2. 登录
export async function login(params: LoginParamsType) {
  return request('/loginManage/login',{
      method:'post',
      body:JSON.stringify(params),
    });
}

// 3. 忘记密码 - 获取短信验证码
export async function getMessageCode(params: GetMessageParamsType) {
  return request('/login/sendMessage', { params });
}

// 4. 忘记密码 - 重新更改密码
export async function forgetLoginKey(params: UpdateKeyParamsType) {
  return request('/login/forgetLoginKey', { method: 'POST', data: params });
}
